#!/bin/bash
#文件备份目录
dateDir=`date +%Y%m%d`

#文件名
dateFile=`date +%M`

#创建redis数据库备份文件夹
mkdir -p /usr/src/redis/backup/${dateDir}

# 查询redis主机保存状态
res=`/usr/local/redis-5.0.3/redis-cli -p 6382 info Persistence | grep rdb_bgsave_in_progress | awk -F: '{print $2}'`

if [ $res==0 ];then
   #redis-master  rdb数据持久化备份文件夹
   cp -r /usr/local/docker/redis/master/dump.rdb  /usr/src/redis/backup/${dateDir}/${dateFile}'.rdb'	
   cp -r /usr/local/docker/redis/master/appendonly.aof  /usr/src/redis/backup/${dateDir}/${dateFile}'.aof'
   
   `find /usr/src/redis/backup  -type f -mmin +1 -name *.rdb  -exec rm -rf {} \; `

   `find /usr/src/redis/backup  -type f -mmin +1 -name *.aof  -exec rm -rf {} \; `
else
   echo "数据库正在备份中"
fi
